import { NgModule } from '@angular/core';
import { RouterModule, Routes, Router, NavigationEnd } from '@angular/router';

import { IndexComponent } from './index/index.component';
import { RechargeComponent } from './recharge/recharge.component';
import { AuthGuard } from './auth/auth.guard';
import { IndexHomeComponent } from './index/home/index.component';
import { LoginComponent } from './page/login/index.component';
import { RegisterComponent } from './page/register/index.component';
import { UserCenterComponent } from './userCenter/userCenter';
import { AgencyComponent } from './index/AGENCY/index.component';
import { OrderComponent } from './index/order/index.component';
import { SecurityComponent } from './userCenter/security';
import { UpdatePwdComponent } from './userCenter/updatePwd';
import { WithdrawComponent } from './userCenter/withdraw';
import { GuideComponent } from './index/FL/index.component';
import { RechargeSuccessComponent } from './recharge/rechargeSuccess';
import { UserInfoActivate } from './core/canActivate/userInfoActivate';
import { IndexActivate } from './core/canActivate/indexActivate';
import { GuideDetailActivate } from './core/canActivate/guideDetailActivate';
import { AgencyDetailActivate } from './core/canActivate/agencyDetailActivate';
import { GzComponent } from './page/gz/index.component';
import { UserDelComponent } from './userCenter/userDetail';
import { SearchComponent } from './page/search/index.component';
import { InvestBalanceComponent } from './index/invest-balance/index.component';
import { MHComponent } from './index/MH/index.component';
import { MhDelComponent } from './index/MH/mh-del/index.component';
import { MhPicDelComponent } from './index/MH/mh-pic-del/index.component';
import { MhListComponent } from './index/MH/mh-list/index.component';
import { WalletTansferComponent } from './index/walletTansfer/index.component';
import { WalletTansferRollOutComponent } from './index/walletTansferRollOut/index.component';
import { WalletListComponent } from './index/walletList/index.component';

const routes: Routes = [
	{
		path: '',
		component: IndexComponent,
		children: [
			{
				path: '',
				component: IndexHomeComponent,
				resolve: {
					indexData: IndexActivate,
				},
			},
			{
				path: 'indexMy',
				component: UserCenterComponent,
			},
			{
				path: 'fl',
				component: GuideComponent
			},
			{
				path: 'mh',
				component: MHComponent
			},
		],
	},
	{ path: 'login', component: LoginComponent },
	{ path: 'register', component: RegisterComponent },
	{ path: 'agency', component: AgencyComponent },
	{ path: 'mhDel', component: MhDelComponent },
	{ path: 'picDel', component: MhPicDelComponent },
	{ path: 'mhList', component: MhListComponent },
	{ path: 'wallettansfer', component: WalletTansferComponent },
	{ path: 'wallettansferRollOut', component: WalletTansferRollOutComponent },
	{ path: 'walletList', component: WalletListComponent },

	{ path: 'jyjl', component: OrderComponent },
	{ path: 'recharge', component: RechargeComponent },
	{ path: 'rechargeSuccess', component: RechargeSuccessComponent },
	{ path: 'investBalance', component: InvestBalanceComponent },
	// { path: 'staticpages', loadChildren: () => import('./staticpages/staticpages.module').then(m => m.StaticpagesModule) }
	{ path: 'security', component: SecurityComponent },
	{ path: 'updatePwd/:type', component: UpdatePwdComponent },
	{ path: 'withdraw', component: WithdrawComponent },
	{ path: 'gz', component: GzComponent },
	{ path: 'userDel', component: UserDelComponent },
	{ path: 'search', component: SearchComponent },
	{ path: 'getAuthorizeCode', component: SearchComponent },
];

@NgModule({
	exports: [RouterModule],
	imports: [RouterModule.forRoot(routes)],
	providers: [AuthGuard, UserInfoActivate, IndexActivate, GuideDetailActivate, AgencyDetailActivate],
	declarations: [],
})
export class AppRoutingModule {

	constructor(
		private router: Router
	) {
		this.router.events
			.subscribe((event) => {
				if (event instanceof NavigationEnd) {
					window.scrollTo({ top: 0 });
				}
			});
	}

}
